﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RMSoftware.Models;
using Entities;

namespace RMSoftware.Controllers
{
    public class RiskController : Controller
    {
        [HttpGet]
        public ActionResult Create(Guid id)
        {
            ViewBag.RiskFactors = (new DataManager()).RiskFactors;

            return View(new Risk { ProjectId = id });
        }

        [HttpPost]
        public ActionResult Create(Risk obj)
        {
            obj.ProjectRiskId = Guid.NewGuid();
            (new DataManager()).SaveRisk(obj);

            return RedirectToAction("ViewDetails", "Project", new { id = obj.ProjectId });
        }

        [HttpGet]
        public ActionResult ViewDetails(Guid id)
        {
            return View((new DataManager()).GetRisk(id));
        }

        [HttpPost]
        public ActionResult ViewDetails(Risk obj)
        {
            (new DataManager()).SaveRisk(obj);

            return RedirectToAction("ViewDetails", "Project", new { id = obj.ProjectId });
        }

        [HttpGet]
        public ActionResult Delete(Guid id)
        {
            DataManager dm = new DataManager();
            Risk pr = dm.GetRisk(id);
            dm.DeleteRisk(pr);

            return RedirectToAction("ViewDetails", "Project", new { id = pr.ProjectId });
        }
    }
}
